﻿using UnityEngine;

namespace Smart.Model
{
    public static class PathHelper
    {
        static string platform = string.Empty;
        public static string getPlatformString()
        {
            if(string.IsNullOrEmpty(platform))
            {
    #if UNITY_IOS
            platform = "iOS";
    #elif UNITY_ANDROID
            platform = "Android";
    #else
            platform = "Editor";
    #endif
            }
            return platform;
        }

        public static string getPersistentPath(string bundleName,bool useWWW)
        {
            if (useWWW)
            {
    #if UNITY_IOS
                return "file://" + Application.persistentDataPath + "/" + bundleName;
    #elif UNITY_ANDROID
                return "file:///" + Application.persistentDataPath + "/" + bundleName;
    #else
                return Application.persistentDataPath + "/" + bundleName;
    #endif
            }
            else
            {
                return Application.persistentDataPath + "/" + bundleName;
            }
        }

        public static string getAssetBundleSavePath(string bundleName, bool useWWW, bool fromStreamingAssets = false)
        {
            if (fromStreamingAssets)
            {
                if (useWWW)
                {

    #if UNITY_EDITOR
                    return "file://" + Application.streamingAssetsPath + "/AssetBundles/" + bundleName;
    #elif UNITY_IOS
                    return "file://" + Application.streamingAssetsPath + "/AssetBundles/" + bundleName;
    #else
                    return Application.streamingAssetsPath + "/AssetBundles/" + bundleName;
    #endif
                }
                else
                {
                    return Application.streamingAssetsPath + "/AssetBundles/" + bundleName;
                }
            }

            if (useWWW)
            {
    #if UNITY_IOS
                return "file://" + Application.persistentDataPath + "/AssetBundles/" + bundleName;
    #elif UNITY_ANDROID
                return "file:///" + Application.persistentDataPath + "/AssetBundles/" + bundleName;
    #else
                return Application.persistentDataPath + "/AssetBundles/" + bundleName;
    #endif
            }
            else
            {
                return Application.persistentDataPath + "/AssetBundles/" + bundleName;
            }
        }

        public static string getStreamingAssetsPath(string path)
        {
    #if UNITY_IOS || UNITY_ANDROID && UNITY_EDITOR
            return @"file://" + System.IO.Path.Combine(Application.streamingAssetsPath, path);
    #else
            return System.IO.Path.Combine(Application.streamingAssetsPath, path);
    #endif
        }
    }
}